#include "Main.h"
#include "Window.h"
#include "2DDevice.h"
#include "Select.h"
#include "AstarPathFind.h"
//#include "HPAPathFind.h"
#include "BinaryHeap.h"
//#include "BinaryHeapForHPA.h"
#include "QuadRenderer.h"
#include "LineRenderer.h"
#ifdef DEBUG_HPA
#include "OpenListDebug.h"
#endif
#include <windows.h>
#include <stdio.h>
#include "Map.h"
#include "Vis.h"
extern cVis * Vis;
extern cWindow * Window;
extern c2DDevice * TwoDDevice;
extern cSelect * Select;
extern cAstarPathFind * AstarPathFind;
extern cBinaryHeap * BinaryHeap;
//extern cBinaryHeapHPA * BinaryHeapHPA;
extern cQuadRenderer * QuadRenderer;
extern cLineRenderer * LineRenderer;
//extern cHPAPathFind * HPAPathFind;
//extern cAbstractGraphRenderer * AbstractGraphRenderer;
extern cMap * Map;
#ifdef DEBUG_HPA
extern cOpenListDebug * OpenListDebug;
#endif
cMain * Main;
cMain::cMain()
{
	State = STATE_PATHFIND;
	TwoDDevice = NULL;
	Select = NULL;
	BinaryHeap = NULL;
	//AbstractGraphRenderer = NULL;
	Window = new cWindow();
	Window->CalculateDimensions();
	TwoDDevice = new c2DDevice();
	Map = new cMap();
	Select = new cSelect();
	Select->Restart();
	Vis = new cVis();
	AstarPathFind = new cAstarPathFind(); 
	BinaryHeap = new cBinaryHeap();
	//BinaryHeapHPA = new cBinaryHeapHPA;
	QuadRenderer = new cQuadRenderer();
	LineRenderer = new cLineRenderer();
	//HPAPathFind = new cHPAPathFind();
	#ifdef DEBUG_HPA
	OpenListDebug = new cOpenListDebug();
	#endif
}

cMain::~cMain()
{


}


void cMain::MainLoop()
{
	
    MSG   msg;
	
    ZeroMemory( &msg, sizeof(msg) );
	//PathFind->FindPath(0,0,6,6);
            while( msg.message!=WM_QUIT )
            {
                if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
                {
                    TranslateMessage( &msg );
                    DispatchMessage( &msg );
                }
                else
                  if(TwoDDevice) TwoDDevice->Render();
				//GetCursorPos(&point);
				//Window->CursorPosX = point.x;
				//Window->CursorPosY = point.y;
				//sprintf(Window->text2, "x: %d, y: %d", point.x, point.y);
				//SendMessage(Window->hwndButton3, WM_SETTEXT, 0, (LPARAM)Window->text2);
			//SetWindowText(cWindow::hWndMainFrame,text);
            }
}